<template>
	<city-select
		class="city-selector"
		@cityClick="cityClick"
		:formatName="formatName"
		:hotCity="hotCity"
		:obtainCitys="obtainCitys"
		:isSearch="true"
	></city-select>
</template>

<script>
import http from '@/common/request.js';
import { mapState } from 'vuex';
import { getCommonShareInfo } from '@/common/utils.js';
export default {
	onShareAppMessage() {
		return getCommonShareInfo();
	},
	data() {
		return {
			add: '',
			//需要构建索引参数的名称（注意：传递的对象里面必须要有这个名称的参数）
			formatName: 'cityName',
			//热门城市
			hotCity: [],
			//显示的城市数据
			obtainCitys: []
			// qqmapsdk:null
		};
	},
	onLoad() {},
	created() {
		this.getHotcity();
		this.getCity();
	},
	computed: {
		...mapState({
			userInfo: state => state.userInfo,
			location: state => state.location,
			currentHouse: state => state.currentHouse
		})
	},
	methods: {
		getCity() {
			http('/api/cusCityInfo/getCity', {
				data: {},
				method: 'GET'
			}).then(result => {
				this.obtainCitys = result.data;
			});
		},
		getHotcity() {
			http('/api/cusCityInfo/getHotCity', {
				data: {},
				method: 'GET'
			}).then(result => {
				this.hotCity = result.data;
			});
		},
		cityClick({ cityName, cityCode }) {
			http('/api/cusUserInfo/saveUserCity', {
				data: {
					areaName: cityName,
					areaCd: cityCode
				},
				method: 'POST'
			}).then(
				result => {
					this.$store.commit('UPDATE_LOCATION', {
						cityName,
						cityCode
					});
				},
				result => {
					this.showLoading = false;
					uni.showToast({
						title: result.msg,
						icon: 'none'
					});
				}
			);

			uni.navigateBack({
				delta: 1,
				animationType: 'pop-out',
				animationDuration: 200
			});
		}
	}
};
</script>

<style lang="less" scoped></style>
